package main

import "fmt"

/*
  策略模式
  在运行时动态地装配算法行为到对象中。可以定义算法，封装它们，动态地切换它们。
*/

//算法抽象
type Operator interface {
	Apply(int,int) int
}
type Operation struct {
	Operator Operator
}

func (o *Operation) Operate(l,r int) int {
	return o.Operator.Apply(l,r)
}

//加法实现
type Addition struct {
}

func (a Addition) Apply(l,r int) int  {
	return l + r
}


func main() {
    o := &Operation{Operator:Addition{}}
    fmt.Println(o.Operate(1,1))
}
